//
//  FDMPushSomeOnePushCollectionViewCell.m
//  Entertainment
//
//  Created by dllo on 16/4/20.
//  Copyright © 2016年 付冬梅. All rights reserved.
//

#import "FDMPushSomeOnePushCollectionViewCell.h"
#import "FDMSomeOnePushModel.h"

@interface FDMPushSomeOnePushCollectionViewCell ()

@property (nonatomic, retain) UILabel *titleLabel;/**< 标题 */

@property (nonatomic, retain) UILabel *subTitleLabel;/**< 副标题 */

@property (nonatomic, retain) UIImageView *imageView;/**< 主图片 */

@end
@implementation FDMPushSomeOnePushCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createCollectionViewCell];
    }
    return self;
}

- (void)dealloc {
    [self.titleLabel release];
    [self.subTitleLabel release];
    [self.imageView release];
    [self.modle release];
    [super dealloc];
}

- (void)createCollectionViewCell {
    self.imageView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.imageView];
    [self.imageView release];
    self.titleLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel release];
    self.subTitleLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.subTitleLabel];
    [self.subTitleLabel release];
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    [super applyLayoutAttributes:layoutAttributes];
    
    self.subTitleLabel.numberOfLines = 2;
    self.subTitleLabel.font = [UIFont systemFontOfSize:14];
    self.titleLabel.backgroundColor = [UIColor blackColor];
    self.titleLabel.alpha = 0.7;
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.font = [UIFont systemFontOfSize:14];
    
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(0);
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-40);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageView.mas_bottom).with.offset(-20);
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
        make.bottom.equalTo(self.imageView.mas_bottom).with.offset(0);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
    }];
    [self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageView.mas_bottom).with.offset(0);
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(0);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
    }];
}

- (void)setModle:(FDMSomeOnePushModel *)modle {
    if (_modle != modle) {
        [_modle release];
        _modle = [modle retain];
        self.titleLabel.text = _modle.title;
        self.subTitleLabel.text = _modle.trackTitle;
        [self.imageView sd_setImageWithURL:[NSURL URLWithString:_modle.coverLarge] placeholderImage:PLACEHOLDER_IMAGE];
    }
}

- (void)setDetailModel:(FDMSomeOnePushModel *)detailModel {
    if (_detailModel != detailModel) {
        [_detailModel release];
        _detailModel = [detailModel retain];
        self.titleLabel.text = _detailModel.title;
        self.subTitleLabel.text = _detailModel.trackTitle;
        [self.imageView sd_setImageWithURL:[NSURL URLWithString:_detailModel.coverLarge] placeholderImage:PLACEHOLDER_IMAGE];
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
